import { Component, OnInit } from '@angular/core'
import { Location } from '@angular/common'
import { CommonUtil } from 'src/app/common/utils/common.util'
import { FeedbackService } from './services/feedback.service'

@Component({
  selector: 'app-feedback',
  templateUrl: './feedback.component.html',
  styleUrls: ['./feedback.component.scss']
})
export class FeedbackComponent implements OnInit {
  // 反馈最长字符
  maxlength = 200
  // 提交按钮启用禁用
  disabled = false
  // 反馈内容
  text = ''

  constructor(private location: Location, private utils: CommonUtil, private service: FeedbackService) {}

  ngOnInit() {}

  // 返回
  onClickLeft() {
    this.location.back()
  }
  // 提交
  submit() {
    let len = this.text.length
    let reqdata = {
      application: 'ApplicationCategory_House_Consumer.WX',
      text: this.text
    }
    if (len === 0) {
      this.utils.info('请输入反馈内容')
      return false
    }
    this.utils.loading('正在提交...')
    this.disabled = true
    this.service.postFeedback(
      reqdata,
      res => {
        this.utils.hide()
        this.disabled = false
        if (res.Success && res.Result) {
          this.utils.success('操作成功')
          setTimeout(() => {
            this.location.back()
          }, 1000)
        }
      },
      () => {
        this.utils.hide()
        this.disabled = false
      }
    )
  }
}
